/**
 * 漆水河 脚手架基础公开课
 * 2022/8/13 --- 2022/12/13
 * 有疑问可加QQ群: 809126489，后续会持续输出与大家一起成长
 */
package com.qishuihe.common.domain.role.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qishuihe.common.domain.role.service.PermissionService;
import com.qishuihe.common.domain.role.entity.PermissionEntity;
import com.qishuihe.common.domain.role.mapper.PermissionMapper;
import com.qishuihe.baseinterface.basevo.vo.ResultPageVO;
import com.qishuihe.outbound.user.PermissionDTO;
import com.qishuihe.outbound.user.QueryPageDTO;
import com.qishuihe.baseinterface.utils.StringUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

@Service
public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, PermissionEntity> implements PermissionService {

    @Override
    public ResultPageVO<PermissionDTO> queryPermission(QueryPageDTO<PermissionDTO> queryPageDTO) {
        PermissionDTO permissionDTO = queryPageDTO.getParamObj();
        Page<PermissionEntity> permissionEntityPage= new Page<>();
        BeanUtils.copyProperties(queryPageDTO,permissionEntityPage);
        LambdaQueryWrapper<PermissionEntity> lambdaQueryWrapper = new LambdaQueryWrapper();
        if(!StringUtil.isEmpty(permissionDTO.getDescription())) {
            lambdaQueryWrapper.like(PermissionEntity::getDescription, permissionDTO.getDescription());
        }
        if(!StringUtil.isEmpty(permissionDTO.getUrl())) {
            lambdaQueryWrapper.like(PermissionEntity::getUrl, permissionDTO.getUrl());
        }
        permissionEntityPage =super.page(permissionEntityPage,lambdaQueryWrapper);
        ResultPageVO<PermissionDTO> resultPageVO = new ResultPageVO<>();
        BeanUtils.copyProperties(permissionEntityPage, resultPageVO);
        return resultPageVO;
    }
}
